package com.example.administrator.yuejian2.model;

import com.example.administrator.yuejian2.RetrofitListener.RetrofitListener;
import com.example.administrator.yuejian2.bean.AttentionBean;
import com.example.administrator.yuejian2.bean.IsAttentionBean;
import com.example.administrator.yuejian2.service.AttentionClubService;
import com.example.administrator.yuejian2.service.CancelAttentionClubService;
import com.example.administrator.yuejian2.service.IsAttentionClubService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static com.example.administrator.yuejian2.other.Url.BASEURL;
import static com.example.administrator.yuejian2.other.Url.URL1;

public class AttentionClubModel {

    private Retrofit retrofit;
    private AttentionClubService attentionClubService;
    private IsAttentionClubService isAttentionClubService;
    private CancelAttentionClubService cancelAttentionClubService;
    public AttentionClubModel()
    {
        retrofit=new Retrofit.Builder()
                .baseUrl(BASEURL+URL1)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        attentionClubService=retrofit.create(AttentionClubService.class);
        isAttentionClubService=retrofit.create(IsAttentionClubService.class);
        cancelAttentionClubService=retrofit.create(CancelAttentionClubService.class);
    }

    public void attentionClub(String user_id, String club_id, final RetrofitListener listener)
    {
        Call<AttentionBean> call=attentionClubService.attentionClub(user_id,club_id);
        call.enqueue(new Callback<AttentionBean>() {
            @Override
            public void onResponse(Call<AttentionBean> call, Response<AttentionBean> response) {
                listener.onSuccess(response.body(),1);
            }

            @Override
            public void onFailure(Call<AttentionBean> call, Throwable t) {
                listener.onFail();
            }
        });
    }

    public void isAttentionclub(String user_id, String club_id, final RetrofitListener listener)
    {
        Call<IsAttentionBean> call=isAttentionClubService.isAttentionClub(user_id, club_id);
        call.enqueue(new Callback<IsAttentionBean>() {
            @Override
            public void onResponse(Call<IsAttentionBean> call, Response<IsAttentionBean> response) {
                listener.onSuccess(response.body(),1);
            }

            @Override
            public void onFailure(Call<IsAttentionBean> call, Throwable t) {
                listener.onFail();
            }
        });
    }
    public void cancelAttentionClub(String user_id, String club_id , final RetrofitListener listener)
    {
        Call<AttentionBean> call=cancelAttentionClubService.cancelAttentionClub(user_id, club_id);
        call.enqueue(new Callback<AttentionBean>() {
            @Override
            public void onResponse(Call<AttentionBean> call, Response<AttentionBean> response) {
                listener.onSuccess(response.body(),1);
            }

            @Override
            public void onFailure(Call<AttentionBean> call, Throwable t) {
                listener.onFail();
            }
        });
    }
}
